import redis

pool = redis.ConnectionPool(host='localhost', port=6379, decode_responses=True)
r = redis.Redis(connection_pool=pool)

# r.lpush("list1", 11, 22, 33)
vncrfb = '/home/a/ou/filter/vncrfb.txt'
nsrdany = '/home/a/ou/filter/dnsrdany.txt'
sipquery = '/home/a/ou/filter/sipquery.txt'
sipregistration = '/home/a/ou/filter/sipregistration.txt'
sshclient = '/home/a/ou/filter/sshclient.txt'
ssh = open(sshclient, 'r', encoding='utf-8')
vnc = open(vncrfb, 'r', encoding='utf-8')
nsr = open(nsrdany, 'r', encoding='utf-8')
sipq = open(sipquery, 'r', encoding='utf-8')
sipr = open(sipregistration, 'r', encoding='utf-8')
pool = [ssh, vnc, nsr, sipr, sipq]
dns = '/home/a/ou/filter/DNS.txt'
d = open(dns, 'r', encoding='utf-8')


def addip():
    for i in pool:
        for lines in i:
            if lines[0] != '#':
                a = lines.split('|')
                r.sadd('ip', a[2].strip())


def dns():
    count = 0
    try:
        for lines in d:
            if lines[0] != '#':
                a = lines.split(' ')[0].split('	')[1]
                count += 1
                r.sadd('dns', a)
    except Exception as e:
        print(e, count)



